﻿namespace NTLib.Pipe.UTest.Targets
{
    using NTLib.Pipe.Descriptors;
    using NTLib.Pipe.Targets;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using Core.Descriptors;

    public class TestTargetDesciption<T> : ITargetDescriptor
    {
        #region Fields

        private readonly Guid _id = Guid.NewGuid();
        private T _value;
        private string _signature;

        #endregion

        #region Ctor
        /// <summary>
        /// Initializes a new instance of the <see cref="TestTargetDesciption{T}"/> class.
        /// </summary>
        /// <param name="value">The value.</param>
        public TestTargetDesciption(T value, string signature)
            : base()
        {
            this._value = value;
            this._signature = signature;
        }

        #endregion

        #region Properties

        /// <summary>
        /// Gets the name.
        /// </summary>
        public string Name
        {
            get { return "Test Descriptor" ; }
        }

        public Guid Id
        {
            get { return new Guid("fceb3929-5a87-44b0-8596-0f3f3b98f681"); }
        }

        /// <summary>
        /// Gets the value.
        /// </summary>
        public T Value
        {
            get { return this._value; }
        }

        /// <summary>
        /// Gets the signature.
        /// </summary>
        public string Signature
        {
            get { return this._signature; }
        }

        #endregion

        #region Methods

        /// <summary>
        /// Equalses the specified other.
        /// </summary>
        /// <param name="other">The other.</param>
        /// <returns></returns>
        public bool Equals(ITargetDescriptor other)
        {
            return other is TestTargetDesciption<T> && ((TestTargetDesciption<T>)other)._id == this._id;
        }

        /// <summary>
        /// Clones this instance.
        /// </summary>
        public IDescriptor Clone()
        {
            return new TestTargetDesciption<T>(this._value, this._signature);
        }

        public bool Equals(IDescriptor other)
        {
            var otherInfo = other as TestTargetDesciption<T>;

            return string.Equals(Name, otherInfo.Name, StringComparison.InvariantCultureIgnoreCase) &&
                   otherInfo.Id == this.Id &&
                   string.Equals(Signature, otherInfo.Signature, StringComparison.InvariantCultureIgnoreCase) &&
                   EqualityComparer<T>.Default.Equals(otherInfo.Value, this.Value);
        }

        #endregion
    }
}
